// 用户标签页
import 'package:flutter/material.dart';
import '../model/api_response.dart';
import '../model/user.dart';
import '../repository/user_repository.dart';

class UserTab extends StatelessWidget {
  final UserRepository userRepo;

  const UserTab({Key? key, required this.userRepo}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return FutureBuilder<ApiResponse<List<User>>>(
      future: userRepo.fetchUsers(),
      builder: (context, snapshot) {
        if (snapshot.connectionState == ConnectionState.waiting) {
          return const Center(child: CircularProgressIndicator());
        }

        if (snapshot.hasError) {
          return Center(child: Text('错误: ${snapshot.error}'));
        }

        final response = snapshot.data!;
        if (response.data == null) {
          return Center(child: Text(response.message));
        }

        final users = response.data!;
        return ListView.builder(
          itemCount: users.length,
          itemBuilder: (context, index) {
            final user = users[index];
            return ListTile(
              title: Text(user.name),
              subtitle: Text(user.email),
            );
          },
        );
      },
    );
  }
}